const mongoose = require('mongoose');

const securitySchema = new mongoose.Schema({
  type: {
    type: String,
    enum: ['access', 'alarm', 'incident', 'patrol'],
    required: true
  },
  level: {
    type: String,
    enum: ['low', 'medium', 'high', 'critical'],
    default: 'low'
  },
  location: {
    building: String,
    floor: String,
    room: String,
    coordinates: { x: Number, y: Number }
  },
  description: {
    type: String,
    required: true
  },
  status: {
    type: String,
    enum: ['open', 'investigating', 'resolved', 'false_alarm'],
    default: 'open'
  },
  reportedBy: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
  },
  assignedTo: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
  },
  resolvedAt: Date,
  evidence: [{
    type: String, // 文件路径
    description: String
  }]
}, {
  timestamps: true
});

module.exports = mongoose.model('Security', securitySchema);
